
BINDIR ?=	/usr/local/sbin
DOCDIR ?=	/usr/local/share/doc
MANDIR ?=	/usr/local/man/cat

.include <bsd.own.mk>

# Do NOT use PROG, we're not C program
PROGNAME =	rb
NOPROG =

DOCS =	CHANGES HACK LICENSE README STYLE UPGRADE
MAN1 =	${SCRIPTS:S/$/.1/}
MAN5 =	${PROGNAME}.5
MAN7 =	${PROGNAME}.7
MAN  =	${MAN1} ${MAN5} ${MAN7}

PACKAGES = \
	RB/Archive.pm \
	RB/Dir.pm \
	RB/Log.pm \
	RB/Profile.pm \
	RB/Remote.pm \
	RB/RotateScheme.pm \
	RB/RotateScheme/Daily.pm \
	RB/RotateScheme/Monthly.pm \
	RB/RotateScheme/Weekly.pm \
	RB/Transfer.pm \
	RB/Util.pm

# Packages being embedded in rb_agent
AGENT_PACKAGES = \
	RB/Transfer.pm

PACKAGEDIRS = \
	RB \
	RB/RotateScheme

SCRIPTS = \
	${PROGNAME}_agent \
	${PROGNAME}_cpanel \
	${PROGNAME}_dump \
	${PROGNAME}_fixinfo \
	${PROGNAME}_restore \
	${PROGNAME}_rotate

SCRIPTS_LNK =
#	from	to

LIBBASE =	/usr/local/libdata/perl5/site_perl

CLEANFILES =	${PROGNAME}_agent

clean:
	rm -f ${CLEANFILES}

${PROGNAME}_agent: rb_agent.in ${AGENT_PACKAGES}
	awk 'NR == 1,    $$0 !~ /^#/ { print; }'  rb_agent.in  >$@
	awk '/^package/, $$0 == "1;" \
		{ if ($$0 != "1;" && $$0 !~ /^[\s]*use RB::/) { print; } }' \
		${AGENT_PACKAGES} >>$@
	awk '/^package/, 1 == 0      { print; }'  rb_agent.in >>$@
	chmod a+x -- $@

all: ${PROGNAME}_agent ${MANALL} ${PSALL}

install: maninstall
.for i in ${PACKAGEDIRS}
	${INSTALL} -d -o ${LIBOWN} -g ${LIBGRP} -m ${DIRMODE} \
		${DESTDIR}${LIBBASE}/$i
.endfor
.for i in ${PACKAGES}
	${INSTALL} ${INSTALL_COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
		${.CURDIR}/$i ${DESTDIR}${LIBBASE}/$i
.endfor
.for i in ${SCRIPTS}
	${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
		${.CURDIR}/$i ${DESTDIR}${BINDIR}/$i
.endfor
.for i j in ${SCRIPTS_LNK}
	cd ${DESTDIR}${BINDIR} && ln -f $i $j
.endfor
	${INSTALL} -d -o ${DOCOWN} -g ${DOCGRP} -m ${DIRMODE} \
		${DESTDIR}${DOCDIR}/${PROGNAME}
.for i in ${DOCS}
	${INSTALL} ${INSTALL_COPY} -o ${DOCOWN} -g ${DOCGRP} -m ${DOCMODE} \
		${.CURDIR}/$i ${DESTDIR}${DOCDIR}/${PROGNAME}/$i
.endfor

.include <bsd.man.mk>
